/**
 * 
 */
package com.ordoict.smallsettlement;

import java.util.HashMap;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import com.ordoict.smallsettlement.common.xml.entity.UnmarshallObject;
import com.ordoict.smallsettlement.common.xml.entity.UnmarshallProperty;
import com.ordoict.smallsettlement.common.xml.loader.Loader;
import com.ordoict.smallsettlement.thread.task.TaskThread;

/**
 * DESC : 
 *
 * @company : OrdoICT.,Inc
 * @author  : Choi Jin Wook // choijinwook84@ordoict.com
 * @version : 1.0.0
 * @since   : 2013. 12. 2.
 * 
 */
public class MainClass {
    
    public static ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
    /**
     * @param args
     */
    public static void main(String[] args) {
        
        ThreadPoolTaskExecutor threadPoolExcutor = (ThreadPoolTaskExecutor)context.getBean("taskExecutor");
        
        Loader loader = new Loader("classpath:telegram/Example.xml");
        
        HashMap<String,UnmarshallObject> a = loader.getMapData();
        
        for(UnmarshallObject u : a.values()){
            System.out.println("@@@@@@@@@@@@@@@@@@@@@@@");
            System.out.println("ID : "+u.getId());
            System.out.println("TYPE : "+u.getType());
            System.out.println("TELEGRAM LENGTH : "+u.getTelegramLength());
            System.out.println("START WITH : "+u.getStartWith());
            
            for(UnmarshallProperty up : u.getProperty()){
                System.out.println("\t$$$$$$$$$$$$$$$$$$$$$$$$");
                System.out.println("\t NAME : "+up.getName());
                System.out.println("\t TYPE : "+up.getType());
                System.out.println("\t LENGTH : "+up.getLength());
                System.out.println("\t START WITH : "+up.getStartWith());
                System.out.println("\t REQUIRED : "+up.isRequired());
            }
        }

        while(true){
            try{
                TaskThread taskThread = (TaskThread)context.getBean("taskThread");
                threadPoolExcutor.execute(taskThread);
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }
    
}
